<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>去掉map相同的边</title>
    <script src="https://unpkg.com/@turf/turf/turf.min.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

</head>
<!-- <script type="module" src="./index.js"></script> -->

<body>

</body>
<script>

    const readFile = (url) => {
        return axios({
            url,
            method: 'get'
        }).then((res) => res.data)
    }

    Promise.all([
        readFile('./guizhou/关岭布依族.json'),
        // readFile('./guizhou/普定县.json'),
        // readFile('./guizhou/西秀区.json'),
        readFile('./guizhou/镇宁布依族.json'),
        // readFile('./guizhou/紫云苗族.json')
    ]).then(res => {

        console.log(res)

        let result = []
        let arr = []
        for (let i = 0; i < res.length; i++) {
            let item = res[i].features
            let arr1 = []
            for (let j = 0; j < item.length; j++) {
                let geometry = item[j].geometry.coordinates
                for (let coord = 0; coord < geometry.length; coord++) {
                    result.push(geometry[coord])
                    arr1.push({
                        "type": "Feature",
                        "geometry": {
                            "type": "Polygon",
                            "coordinates": geometry[coord]
                        }
                    })
                }
            }
            arr.push(...arr1)
        }

        console.log(arr)



        const opt = {
            "type": "FeatureCollection",
            // "features": [
            //     {
            //         "type": "Feature",
            //         "geometry": {
            //             "type": "Polygon",
            //             "coordinates": result
            //         }
            //     }
            // ]
            "features": arr
        }

        console.log(result)
        console.log(opt)
        const mergedFeatures = turf.dissolve(opt);
        console.log(mergedFeatures)
    })



    var features = turf.featureCollection([
        turf.polygon([[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]], { combine: 'yes' }),
        turf.polygon([[[0, -1], [0, 0], [1, 0], [1, -1], [0, -1]]], { combine: 'yes' }),
        turf.polygon([[[1, -1], [1, 0], [2, 0], [2, -1], [1, -1]]], { combine: 'yes' }),
    ]);
    // , { propertyName: 'combine' }
    var dissolved = turf.dissolve(features);
    console.log(features)
    console.log(dissolved)



</script>

</html>